package com.lejin.usercenter.controller;

import com.lejin.interceptor.UserInfoInterceptor;
import com.lejin.usercenter.entity.SysUser;
import com.lejin.usercenter.service.ISysUserService;
import com.lejin.vo.CheckPwdVo;
import com.lejin.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author luminghua
 * @since 2022-04-21
 */
@CrossOrigin
@RestController
@RequestMapping("/usercenter/sys-user")
public class SysUserController {



    @Autowired
    private UserInfoInterceptor userInfoInterceptor;
    @Autowired
    private ISysUserService iSysUserService;
    //查询用户信息
    @RequestMapping("list")
    public ResultVO list(){

        ResultVO sysUserByUid = iSysUserService.findSysUserByUid(userInfoInterceptor.getThreadLocal().get());
        return sysUserByUid;

    }

    //根据id修改用户基本信息



    @PostMapping("update")
    public ResultVO add(@RequestBody(required = false) SysUser sysUser){
        System.out.println("进来了");
        return iSysUserService.updateSysUser(sysUser);

    }

    //检查密码
    @PostMapping("check")
    public ResultVO check(@RequestBody CheckPwdVo checkPwdVo){

        return iSysUserService.checkPwd(checkPwdVo);


    }

    //修改密码
    @PostMapping("changePwd")
    public ResultVO changePwd(@RequestBody CheckPwdVo checkPwdVo){

        return iSysUserService.changePwd(checkPwdVo);


    }


    //上传用户头像
    @PostMapping("avatUpload")
    public ResultVO avatUpload(@RequestParam("avtImg") MultipartFile avtImg, HttpServletRequest request){

        return iSysUserService.avatUpload(avtImg,request);
    }
}
